home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
programming
/
other
/
jikes
/
src
/
semantic.h
< prev
next >
Wrap
C/C++ Source or Header
|
1999-05-14
|
53KB
|
1,174 lines
// $Id: semantic.h,v 1.10 1999/03/10 19:59:21 shields Exp $
//
// This software is subject to the terms of the IBM Jikes Compiler
// License Agreement available at the following URL:
// http://www.ibm.com/research/jikes.
// Copyright (C) 1996, 1998, International Business Machines Corporation
// and others. All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
#ifndef semantic_INCLUDED
#define semantic_INCLUDED
#include "config.h"
#ifndef __amigaos__
#include <wchar.h>
#endif
#include "ast.h"
#include "diagnose.h"
#include "error.h"
#include "symbol.h"
#include "control.h"
#include "tuple.h"
#include "set.h"
class cp_info;
class TypeShadowSymbol;
//
//
//
class SymbolTableStack
{
public:
void Push(SymbolTable *symtab) { table.Next() = symtab; }
void Pop() { if (table.Length() > 0) table.Reset(table.Length() - 1); }
int Size() { return table.Length(); }
SymbolTable *Top() { return (SymbolTable *) (table.Length() > 0 ? table[table.Length() - 1] : NULL); }
SymbolTable *operator[](const int i) { return table[i]; } /* */
//
// Search for a variable in a stack of symbol tables starting at the current symbol table
// and ending with the symbol table of the method from which this call originates.
//
VariableSymbol *FindVariableSymbol(NameSymbol *name_symbol)
{
for (int i = table.Length() - 1; i >= 0; i--)
{
VariableSymbol *symbol = table[i] -> FindVariableSymbol(name_symbol);
if (symbol)
return symbol;
}
return (VariableSymbol *) NULL;
}
//
// Search for a type in a stack of symbol tables starting at the current symbol table
// and ending with the symbol table of the method from which this call originates.
//
TypeSymbol* FindTypeSymbol(NameSymbol *name_symbol)
{
for (int i = table.Length() - 1; i >= 0; i--)
{
TypeSymbol *symbol = table[i] -> FindTypeSymbol(name_symbol);
if (symbol)
return symbol;
}
return (TypeSymbol *) NULL;
}
//
// Search for a label in a stack of symbol tables starting at the current symbol table
// and ending with the symbol table of the method from which this call originates.
//
LabelSymbol* FindLabelSymbol(NameSymbol *name_symbol)
{
for (int i = table.Length() - 1; i >= 0; i--)
{
LabelSymbol *label = table[i] -> FindLabelSymbol(name_symbol);
if (label)
return label;
}
return (LabelSymbol *) NULL;
}
private:
Tuple<SymbolTable *> table;
};
//
//
//
class ExceptionTableStack
{
public:
void Push(SymbolSet *set) { table.Next() = set; }
void Pop() { if (table.Length() > 0) table.Reset(table.Length() - 1); }
int Size() { return table.Length(); }
SymbolSet *Top() { return (SymbolSet *) (table.Length() > 0 ? table[table.Length() - 1] : NULL); }
private:
Tuple<SymbolSet *> table;
};
//
//
//
class StatementStack
{
public:
void Push(Ast *stmt) { info.Next() = stmt; }
void Pop() { if (info.Length() > 0) info.Reset(info.Length() - 1); }
int Size() { return info.Length(); }
Ast *Top() { return (Ast *) (info.Length() > 0 ? info[info.Length() - 1] : NULL); }
Ast *operator[](const int i) { return info[i]; }
private:
Tuple<Ast *> info;
};
//
//
//
class BlockStack
{
public:
int max_size;
void Push(AstBlock *block_)
{
block.Next() = block_;
index.Next() = 0;
if (block.Length() > max_size)
max_size = block.Length();
}
void Pop()
{
int len = block.Length() - 1;
if (len >= 0)
{
block.Reset(len);
index.Reset(len);
}
}
int Size() { return block.Length(); }
AstBlock *TopBlock() { return (AstBlock *) (block.Length() > 0 ? block[block.Length() - 1] : NULL); }
AstBlock *operator[](const int i) { return block[i]; }
int &TopMaxEnclosedVariableIndex()
{
if (index.Length() <= 0)
assert(0);
return index[index.Length() - 1];
}
BlockStack() : max_size(0) {}
private:
Tuple<AstBlock *> block;
Tuple<int> index;
};
//
//
//
class DefiniteFinalAssignmentStack
{
public:
void Push() { info.Next().Reset(); }
void Pop() { if (info.Length() > 0) info.Reset(info.Length() - 1); }
int Size() { return info.Length(); }
Tuple <AstExpression *> &Top() { if (info.Length() == 0) assert(0); return info[info.Length() - 1]; }
private:
Tuple< Tuple<AstExpression *> > info;
};
//
//
//
class DefiniteSets
{
public:
DefiniteSets(int set_size) : break_set(set_size),
continue_set(set_size),
return_set(set_size),
throw_set(set_size)
{}
BitSet break_set,
continue_set,
return_set,
throw_set;
void UniverseInit()
{
break_set.SetUniverse();
continue_set.SetUniverse();
return_set.SetUniverse();
throw_set.SetUniverse();
}
void EmptyInit()
{
break_set.SetEmpty();
continue_set.SetEmpty();
return_set.SetEmpty();
throw_set.SetEmpty();
}
};
//
//
//
class DefiniteBlockStack
{
public:
void Push(AstBlock *block_)
{
definite_sets[top_index] -> UniverseInit();
final_sets[top_index] -> EmptyInit();
block[top_index] = block_;
top_index++;
}
void Pop()
{
if (top_index > 0)
top_index--;
else assert(0);
}
int Size() { return top_index; }
AstBlock *Block(int i) { return block[i]; }
AstBlock *TopBlock() { assert(top_index > 0); return block[top_index - 1]; }
BitSet &BreakSet(int i) { return definite_sets[i] -> break_set; }
BitSet &ContinueSet(int i) { return definite_sets[i] -> continue_set; }
BitSet &ReturnSet(int i) { return definite_sets[i] -> return_set; }
BitSet &ThrowSet(int i) { return definite_sets[i] -> throw_set; }
BitSet &TopBreakSet() { assert(top_index > 0); return definite_sets[top_index - 1] -> break_set; }
BitSet &TopContinueSet() { assert(top_index > 0); return definite_sets[top_index - 1] -> continue_set; }
BitSet &TopReturnSet() { assert(top_index > 0); return definite_sets[top_index - 1] -> return_set; }
BitSet &TopThrowSet() { assert(top_index > 0); return definite_sets[top_index - 1] -> throw_set; }
BitSet &TopExitSet(BitSet &start_set)
{
assert(top_index > 0);
exit_set = start_set;
exit_set *= TopBreakSet();
exit_set *= TopContinueSet();
exit_set *= TopReturnSet();
exit_set *= TopThrowSet();
return exit_set;
}
BitSet &FinalBreakSet(int i) { return final_sets[i] -> break_set; }
BitSet &FinalContinueSet(int i) { return final_sets[i] -> continue_set; }
BitSet &FinalReturnSet(int i) { return final_sets[i] -> return_set; }
BitSet &FinalThrowSet(int i) { return final_sets[i] -> throw_set; }
BitSet &TopFinalBreakSet() { assert(top_index > 0); return final_sets[top_index - 1] -> break_set; }
BitSet &TopFinalContinueSet() { assert(top_index > 0); return final_sets[top_index - 1] -> continue_set; }
BitSet &TopFinalReturnSet() { assert(top_index > 0); return final_sets[top_index - 1] -> return_set; }
BitSet &TopFinalThrowSet() { assert(top_index > 0); return final_sets[top_index - 1] -> throw_set; }
BitSet &TopFinalExitSet(BitSet &start_set)
{
assert(top_index > 0);
exit_set = start_set;
exit_set += TopFinalBreakSet();
exit_set += TopFinalContinueSet();
exit_set += TopFinalReturnSet();
exit_set += TopFinalThrowSet();
return exit_set;
}
DefiniteBlockStack(int stack_size_, int set_size) : stack_size(stack_size_),